﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DR.WebUI.Models.Project;

namespace DR.WebUI.Code.ModelBinders
{
    public class ProjectFilterModelBinder : IModelBinder
    {
        private readonly string projectFilterSessionKey = "_ProjectFilter";

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            ProjectFilter projectFilter = (ProjectFilter)controllerContext.HttpContext.Session[projectFilterSessionKey];
            if (projectFilter == null)
            {
                projectFilter = new ProjectFilter();
                controllerContext.HttpContext.Session[projectFilterSessionKey] = projectFilter;
            }
            return projectFilter;
        }
    }
}